<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<style>
<!--
input{
-webkit-appearance: textfield;
    background-color: #ffffff;
    -webkit-rtl-ordering: logical;
    user-select: text;
    cursor: auto;
    padding: 1px;
    border-width: 0px;
    /* border-style: inset; */
    /* border-color: initial; */
    /* border-image: initial; */
    box-sizing: border-box;
}
-->
</style>
<div style="padding:10px 10px 10px 10px">
	<form id="itemeCatEditForm" class="itemForm" method="post">
		<input type="hidden" name="id"/>
	    <table cellpadding="5">
	        <tr>
	            <td>商品类目:</td>
	            <td>
	            	<input type="text" id ="itemCatId" name="id" disabled="disabled"/>
	            	<input type="text" id="itemCatName" name="text" disabled="disabled"/>
	            </td>
	        </tr>
	        <tr>
	            <td>商品图片:</td>
	            <td>
	            	<a href="javascript:void(0)" class="easyui-linkbutton picFileUploadcatadd">上传图片</a>
	                <input type="hidden" name="photoX" id="hiddenPhotoX"/>
	            </td>
	        </tr>
	    </table>
	</form>
	<div style="padding:5px">
	    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">提交</a>
	</div>
</div>
<script type="text/javascript">	
	function submitForm(){
		if(!$('#itemeCatEditForm').form('validate')){
			$.messager.alert('提示','表单还未填写完成!');
			return ;
		}	
		var id = $("#itemCatId").val()
		var photox = $("#hiddenPhotoX").val()
		console.log("dasfas" + id +"---"+photox)
		if(photox.indexOf(",")>=0){
			$.messager.confirm('确认上传', '由于本功能只需要一张图片，因此只有第一张被保存，您确认上传吗', function(r){
				if (r){
					photox =  photox.split(",")[0]
					postPhoto(id,photox)
				}
			});
		}else{
			postPhoto(id,photox)
		}

	}
	function postPhoto(id,photox){
		$.post("./item/cat/update",{'id':id,'photoX':photox}, function(data){
			console.log("修改商品成功"+ data)
			if(data.status == 200){
				$.messager.alert('提示','修改商品成功!','info',function(){
					$("#itemCatEditWindow").window('close');
					$("#tg").treegrid("reload");
				});
			}
		});
	}
</script>
